﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.BLL;
using KPIS.GERP.GIMS.DAL;
using KPIS.GERP.GIMS.IBLL;
using KPIS.GERP.GIMS.MODEL;
using System.Data;

namespace KPIS.GERP.GIMS.APP.APP_UI.Form
{
    public partial class ICM_Dispenses : System.Web.UI.Page
    {
            CommandControl cmdFac = new CommandControl();
            IBLLMasterWarehouse bll = new MasterWarehouseBLL();
            IBLLHrmScope bllHrmScope = new HrmScopeBLL();
            IBLLMasterWarehouseConsume bllConsume = new MasterWarehouseConsumeBLL();
            DispenseDAL disDAL = new DispenseDAL();
            Common.Main cn = new Common.Main();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDataGrid();
            }
        }

        public void LoadDataGrid()
        {
            DataSet ListDataCommand = disDAL.GetDispense((int?)null, (int?)null);
            DataTable table = ListDataCommand.Tables[0];

            DataGrid.DataSource = table;// ListDataCommand.Tables[0];
            DataGrid.DataBind();
            cmdFac.GridCommand(panelList, panelGrid, panelCommand);
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            //IList<MasterWarehouseInfo> infoList = new List<MasterWarehouseInfo>();
            //if (panelGrid.Visible)
            //{
            //    foreach (GridDataItem data in DataGrid.MasterTableView.GetSelectedItems())
            //    {
            //        MasterWarehouseInfo info = new MasterWarehouseInfo();
            //        RecordInfo infoRecord = new RecordInfo();
            //        info.Seq = Convert.ToInt32(data.OwnerTableView.DataKeyValues[data.ItemIndex]["Seq"]);
            //        infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
            //        infoRecord.Updated_when = DateTime.Now;
            //        info.InfoRecord = infoRecord;
            //        infoList.Add(info);
            //    }
            //}
            //else
            //{
            //    MasterWarehouseInfo info = new MasterWarehouseInfo();
            //    RecordInfo infoRecord = new RecordInfo();
            //    info.Seq = Convert.ToInt32(hdSeq.Value);
            //    infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
            //    infoRecord.Updated_when = DateTime.Now;
            //    info.InfoRecord = infoRecord;
            //    infoList.Add(info);
            //}

            //if (infoList.Count == 0)
            //{
            //    RadManager1.Alert(SystemInfo._DeleteNull);
            //    return;
            //}

            //try
            //{
            //    bll.DeleteAll(infoList);
            //}
            //catch
            //{
            //    RadManager1.Alert(SystemInfo._DeleteError);
            //    return;
            //}

            LoadDataGrid();
        }

        protected void DataGrid_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadDataGrid();
        }

        protected void RadManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            LoadDataGrid();
        }

        protected void OnAjaxRequest(object sender, AjaxRequestEventArgs e)
        {
           RadAjaxPanel1.Controls.Add(Page.LoadControl("../UserControl/Personal_Data.ascx"));
        }

        protected void clearFilter_Click(object sender, EventArgs e)
        {
            foreach (GridColumn column in DataGrid.MasterTableView.Columns)
            {
                column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column.CurrentFilterValue = string.Empty;
            }
            DataGrid.MasterTableView.FilterExpression = string.Empty;
            LoadDataGrid();
        }
    }
}
